<?php
// +----------------------------------------------------------------------
// | 海豚PHP框架 [ DolphinPHP ]
// +----------------------------------------------------------------------
// | 版权所有 2016~2017 河源市卓锐科技有限公司 [ http://www.zrthink.com ]
// +----------------------------------------------------------------------
// | 官方网站: http://dolphinphp.com
// +----------------------------------------------------------------------
// | 开源协议 ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------

namespace app\index\controller;

/**
 * 前台首页控制器
 * @package app\index\controller
 */
class Index extends Basic
{
    public function index()
    {
        // 默认跳转模块
        if (config('home_default_module') != 'index') {
            $this->redirect(config('home_default_module'). '/index/index');
        }
        $config=[
            'type'      => 'page\page',
            'var_page'  => 'page'
        ];
        $writers=db("blog_writer")->order("id desc")->paginate(5,false,$config);
        $this->assign("writers",$writers);
        return view();
    }
    public function bloglist(){
        //接收类别id
        $cid=input("cid");
        //接收作者id
        $wid=input("wid");
        if($cid){
            $where="cid=".$cid;
        }elseif ($wid){
            $where="wid=".$wid;
        }else{
            $where="";
        }
        //配置分页参数
        $config=[
            'type'      => 'page\page',
            'var_page'  => 'page'
        ];
        $pagelist=db("blog_article")->order("count desc")->where($where)->paginate(10,false,$config);
        $this->assign("pagelist",$pagelist);
        return view();
    }
    public function blog(){
        $aid=input("aid");
        //点击量+1
        db("blog_article")->where("id=".$aid)->setInc("count");
        //获取文章数据
        $rs=db("blog_article")->where("id=".$aid)->find();
        $wid=$rs["wid"];
        $cid=$rs["cid"];
        $this->assign("rs",$rs);
        //获取作者数据
        $writer=db("blog_writer")->where("id=".$wid)->find();
        $this->assign("writer",$writer);
        //获取类别
        $category=db("blog_category")->where("id=".$cid)->find();
        $this->assign("category",$category);
        //获取文章图片信息
        $aimg=db("blog_pic")->where("aid=".$aid)->select();
        $this->assign("aimg",$aimg);
        return view();
    }
    public function blogimglist(){
        $blogimg=db("blog_pic")->order("id desc")->select();
        $this->assign("blogimg",$blogimg);
        return view();
    }
}
